﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace LootPoints
{
    public partial class RaidScore
    {
        public int? Total
        {
            get
            {
                ModelContainer context = new ModelContainer();
                RSReference reference = context.RSReference.FirstOrDefault();
                if (reference == null) throw new Exception("No rules defined");
                else
                {
                    int? value = 0;
                    value = value + (A01 * reference.A01P);
                    value = value + (A02 * reference.A02P);
                    value = value + (A03 * reference.A03P);
                    value = value + (A04 * reference.A04P);
                    value = value + (A05 * reference.A05P);
                    value = value + (A06 * reference.A06P);
                    value = value + (A07 * reference.A07P);
                    value = value + (A08 * reference.A08P);
                    value = value + (A09 * reference.A09P);
                    value = value + (A10 * reference.A10P);
                    value = value + (A11 * reference.A11P);
                    value = value + (A12 * reference.A12P);
                    value = value + (A13 * reference.A13P);
                    value = value + (A14 * reference.A14P);
                    value = value + (A15 * reference.A15P);
                    return value;
                }
            }
        }

        public int? Average
        {
            get
            {
                ModelContainer context = new ModelContainer();
                RSReference reference = context.RSReference.FirstOrDefault();
                if (reference == null) throw new Exception("No rules defined");
                else
                {
                    int? amount = 0;
                    if (reference.A01P > 0) amount++;
                    if (reference.A02P > 0) amount++;
                    if (reference.A03P > 0) amount++;
                    if (reference.A04P > 0) amount++;
                    if (reference.A05P > 0) amount++;
                    if (reference.A06P > 0) amount++;
                    if (reference.A07P > 0) amount++;
                    if (reference.A08P > 0) amount++;
                    if (reference.A09P > 0) amount++;
                    if (reference.A10P > 0) amount++;
                    if (reference.A11P > 0) amount++;
                    if (reference.A12P > 0) amount++;
                    if (reference.A13P > 0) amount++;
                    if (reference.A14P > 0) amount++;
                    if (reference.A15P > 0) amount++;
                    return Total / amount;
                }
            }
        }

        public List<int?> List
        {
            get
            {
                List<int?> points = new List<int?>();

                if (A01 != null) points.Add(A01);
                if (A02 != null) points.Add(A02);
                if (A03 != null) points.Add(A03);
                if (A04 != null) points.Add(A04);
                if (A05 != null) points.Add(A05);
                if (A06 != null) points.Add(A06);
                if (A07 != null) points.Add(A07);
                if (A08 != null) points.Add(A08);
                if (A09 != null) points.Add(A09);
                if (A10 != null) points.Add(A10);
                if (A11 != null) points.Add(A11);
                if (A12 != null) points.Add(A12);
                if (A13 != null) points.Add(A13);
                if (A14 != null) points.Add(A14);
                if (A15 != null) points.Add(A15);

                return points;
            }
            set
            {
                A01 = value[0];
                A02 = value[1];
                A03 = value[2];
                A04 = value[3];
                A05 = value[4];
                A06 = value[5];
                A07 = value[6];
                A08 = value[7];
                A09 = value[8];
                A10 = value[9];
                A11 = value[10];
                A12 = value[11];
                A13 = value[12];
                A14 = value[13];
                A15 = value[14];
            }
        }
    }
}